// JavaScript Document
$(document).on( 'pageinit', '#uebersicht',function(event){
	var urlServer = 'http://christiansislak.hostignition.com/kilometerpauschale/kilometerpauschale/backend/php/listview.php';
	var urlLocal = 'kilometerpauschale/backend/php/listview.php';
	//$.getJSON( urlServer + '?list=worklist&detail=main', function(data) {
//		console.log(data);
//		
//			$("#mainlistwork").append(data);
//			$("#mainlistwork").listview("refresh");
//	});
	
	$.ajax({
		type: "POST",
		url: urlServer,
		data: ({ list : "worklist", detail: "main" }),
		dataType:"text",
		success: function(data) {
			$("#mainlistwork").append(data);
			$("#mainlistwork").listview("refresh");
		}
	});
	
	$.ajax({
		type: "POST",
		url: urlServer,
		data: ({ list : "privatelist", detail: "main" }),
		dataType:"text",
		success: function(data) {
			$("#mainlistprivate").append(data);
			$("#mainlistprivate").listview("refresh");
		}
	});
});


$(document).on( 'pageinit', '#listviewmonth',function(event){
	var $page = $('#listviewmonth');
	$page.find('#listcontain').empty().html('<ol data-role="listview" data-inset="true" id="listdetailviewmonth">');
	
	var $list = $page.find("#listcontain ol");
	$list.append('<li data-role="list-divider">Monate</li>');
	
	var urlServer = 'http://christiansislak.hostignition.com/kilometerpauschale/kilometerpauschale/backend/php/listview.php';
	var urlLocal = '../backend/php/listview.php';
	
	$.ajax({
		type: "POST",
		url: urlServer,
		data: ({ list : "worklist", detail: "month" }),
		dataType:"text",
		success: function(data) {
			data += '</ol>';
			var items = $(data);
			$list.append(items);
			$list.listview( );
		}
	});
	
	$list.on('click', '#month_click', function() {
		localStorage.choosenMonth = "";
		localStorage.choosenMonth = $(this).find("h3").text();
	});	
});

$(document).on( 'pageshow', '#listviewday',function(event){
	var $page = $('#listviewday');
	$page.find('#listcontain').empty().html('<ol data-role="listview" data-inset="true" id="listdetailviewday">');
	
	var $list = $page.find("#listcontain ol");
	$list.append('<li data-role="list-divider">'+localStorage.choosenMonth+'</li>');
	
	var urlServer = 'http://christiansislak.hostignition.com/kilometerpauschale/kilometerpauschale/backend/php/listview.php';
	var urlLocal = '../backend/php/listview.php';
	
	$.ajax({
		type: "POST",
		url: urlServer,
		data: ({ list : "worklist", detail: "day" }),
		dataType:"text",
		success: function(data) {
			data += '</ol>';
			var items = $(data);
			$list.append(items);
			$list.listview( );
		}
	});
});
